﻿using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using IterationLife.Extensions.Dtos;
using Util.Domains;

namespace IterationLife.ContentResources.Models {
    /// <summary>
    /// 内容资源图集
    /// </summary>
    [Description( "内容资源图集" )]
    public partial class ContentResourcePicture : EntityBase<ContentResourcePicture,Guid> {
        /// <summary>
        /// 初始化内容资源图集
        /// </summary>
        public ContentResourcePicture() : this( Guid.Empty ) {
        }

        /// <summary>
        /// 初始化内容资源图集
        /// </summary>
        /// <param name="id">内容资源图集标识</param>
        public ContentResourcePicture( Guid id ) : base( id ) {
            Picture = new Resources();
        }

        /// <summary>
        /// 内容资源编号
        /// </summary>
        public Guid? ContentResourceId { get; set; }
        /// <summary>
        /// 单封面图
        /// </summary>
        [NotMapped]
        public Resources Picture { get; set; }
        /// <summary>
        /// 图片Json字符串
        /// </summary>
        [Required(ErrorMessage = "图片Json字符串不能为空")]
        [StringLength(300, ErrorMessage = "图片Json字符串输入过长，不能超过300位")]
        public string PictureJsonStr
        {
            get => Util.Json.ToJson(Picture);
            set => Picture = Util.Json.ToObject<Resources>(value);
        }
        /// <summary>
        /// 说明
        /// </summary>
        [StringLength( 1000, ErrorMessage = "说明输入过长，不能超过1000位" )]
        public string Explain { get; set; }
        /// <summary>
        /// 排序号
        /// </summary>
        public int? SortId { get; set; }
        
        /// <summary>
        /// 内容资源
        /// </summary>
        public virtual ContentResource ContentResource { get; set; }
        
        /// <summary>
        /// 添加描述
        /// </summary>
        protected override void AddDescriptions() {
            AddDescription( "内容资源图集编号", Id );
            AddDescription( "内容资源编号", ContentResourceId );
            AddDescription( "图片", Picture );
            AddDescription( "说明", Explain );
            AddDescription( "排序号", SortId );
        }
        
        /// <summary>
        /// 添加变更列表
        /// </summary>
        protected override void AddChanges( ContentResourcePicture newEntity ) {
            AddChange( "Id", "内容资源图集编号", Id, newEntity.Id );            
            AddChange( "ContentResourceId", "内容资源编号", ContentResourceId, newEntity.ContentResourceId );
            AddChange( "Picture", "图片", Picture, newEntity.Picture );
            AddChange( "Explain", "说明", Explain, newEntity.Explain );
            AddChange( "SortId", "排序号", SortId, newEntity.SortId );
        }
    }
}